#include "hex_disp.h"
#include "stddef.h"
#include <stdio.h>
#include <stdlib.h>

char* hex_to_string_malloc(const void* buff, int len)
{
    if (!buff && len <= 0) {
        return NULL;
    }

    char* out  = malloc(len * 3 + 8);
    int   diff = 0;

    for (int i = 0; i < len; i++) {
        diff += sprintf(out + diff, "%02x ", ((uint8_t*)buff)[i]);
    }
    return out;
}

void hex_to_string_free(char* buff)
{
    if (buff) {
        free(buff);
    }
}
